package com.zyy.smartcity1129.movecar;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.MoveCarInfo;
import com.zyy.smartcity1129.util.RvAd;

import java.util.List;

/**
 * @ClassName: MoveRecordFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 4/12/2021$
 * @Version: 1.0
 */
public class MoveRecordFragment extends BaseFragment {
    private RecyclerView rvMoveRecord;
    private TextView tvEmptyToast;
    private RvAd<MoveCarInfo> rvAd;
    private List<MoveCarInfo> list;

    @Override
    protected int layId() {
        return R.layout.f_move_record;
    }

    @Override
    protected String title() {
        return null;
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        MoveCarFragment.mutableMoveCar.postValue("历史记录");
        initView(iv);
        initData();
        if (list.size() != 0) {
            tvEmptyToast.setVisibility(View.GONE);
            initAdapter();
        } else {
            tvEmptyToast.setVisibility(View.VISIBLE);
        }
    }

    private void initAdapter() {
        rvAd = new RvAd<MoveCarInfo>(list, R.layout.rv_moverecord) {
            private TextView tvRvCarNum, tvRvPhone, tvRvAddress;
            private void initView(View v) {
                tvRvCarNum = v.findViewById(R.id.tvRvCarNum);
                tvRvPhone = v.findViewById(R.id.tvRvPhone);
                tvRvAddress = v.findViewById(R.id.tvRvAddress);
            }
            @Override
            protected void initR(View vi, MoveCarInfo moveCarInfo, int p) {
                initView(vi);
                tvRvCarNum.setText(moveCarInfo.getCarnum());
                tvRvPhone.setText(moveCarInfo.getPhone());
                tvRvAddress.setText(moveCarInfo.getAddress());
            }
        };
        rvMoveRecord.setAdapter(rvAd);
        rvMoveRecord.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initData() {
        list = new MoveCarDataAdapter().QueryAll(getContext());
    }

    private void initView(View iv) {
        rvMoveRecord = (RecyclerView) iv.findViewById(R.id.rvMoveRecord);
        tvEmptyToast = (TextView) iv.findViewById(R.id.tvEmptyToast);
    }
}
